﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GMaps;
using BLGPS;

public partial class ConsultarRecorridos : BasePage
{
    public override Perfil Perfil { get { return Perfil.Empresa; } }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Titulo = "Consultar Recorridos";
           GMap map = new GMap();
            map.Center=new GLatLng(-31.400F,-64.183F);
            map.DIV = "divMap";
            map.ID = "map";
            map.Zoom = 12;

            GPolyline line = new GPolyline("line");
           

            line.Path.Add(new GLatLng(-31.33F, -64.31F));
            line.Path.Add(new GLatLng(-31.36F, -64.3F));
            line.Path.Add(new GLatLng(-31.43F, -64.27F));
            line.Path.Add(new GLatLng(-31.45F, -64.1F));



            string script = map.Render();

            script += "\n\r\n\r" + line.Render(map);

            GEvent mapClick = new GEvent(map, GEventTypes.Click);
            mapClick.HandlerCode = "alert(event.latLng);";

            script += mapClick.Render();

            script += new GMarker("marker", map, map.Center, "Prueba").Render();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "", script, true);

        }

        
        
    }

    protected void cFiltros_Consultar()
    {
        List<ColeccionMovimiento> recorridos = ColeccionMovimiento.ObtenerPorPeriodo(cFiltros.FechaDesde,cFiltros.FechaHasta ,cFiltros.VehiculosSeleccionados);

        List<GPolyline> lines = new List<GPolyline>();
        GPolyline line;
        
        foreach (var rec in recorridos)
        {
            line = new GPolyline("line"+rec.Vehiculo.Id);
            
            foreach (var mov in rec)
            {
                line.Path.Add(new GLatLng((float)mov.Latitud, (float)mov.Longitud));     
            }
            lines.Add(line);
        }

        RenderMap(lines);

    }

    private void RenderMap(List<GPolyline> lines)
    {
        GMap map = new GMap();
        map.Center = new GLatLng(-31.400F, -64.183F);
        map.DIV = "divMap";
        map.ID = "map";
        map.Zoom = 12;

        string script = map.Render();
        foreach (var line in lines)
        {
            script += "\n\r\n\r" + line.Render(map);
        }

        ScriptManager.RegisterStartupScript(this, this.GetType(), "", script, true);
    }    
   
}